<template>
    <el-container class="layout">
        <el-header class="layout-header">
            <div class="logo">
                <div class="collapse" @click="toggleCollapse">
                    <el-icon>
                        <Menu />
                    </el-icon>
                </div>
                <!-- 这里需要一个logo -->
                <!-- <img src="/path/to/logo.png" alt="Logo" height="40" /> -->
                <span class="brand-name">后台管理系统</span>
            </div>
            <div class="user-info">
                <el-dropdown trigger="hover">
                    <span class="el-dropdown-link">
                        <el-avatar size="small" :src="userAvatar"></el-avatar>
                        <span class="username">{{ userName }}</span>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="navigateTo('/admin/profile')">
                                个人资料
                            </el-dropdown-item>
                            <el-dropdown-item @click="navigateTo('/admin/settings')">
                                设置
                            </el-dropdown-item>
                            <el-dropdown-item divided>退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </el-header>
        <el-container>
            <el-aside class="layout-aside" :width="isCollapse ? '64px' : '200px'">
                <el-menu :default-active="activeMenu" :collapse="isCollapse" router>
                    <el-menu-item index="/admin/home">
                        <el-icon>
                            <HomeFilled />
                        </el-icon>
                        <span>首页</span>
                    </el-menu-item>

                    <el-sub-menu index="user">
                        <template #title>
                            <el-icon>
                                <User />
                            </el-icon>
                            <span>用户管理</span>
                        </template>
                        <el-menu-item index="/admin/users">用户列表</el-menu-item>
                        <el-menu-item index="/admin/roles">角色管理</el-menu-item>
                        <el-menu-item index="/admin/permissions">权限管理</el-menu-item>
                    </el-sub-menu>
                </el-menu>
            </el-aside>

            <el-main class="layout-main">
                <router-view />
            </el-main>
        </el-container>
    </el-container>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const route = useRoute();
const router = useRouter();
const activeMenu = ref(route.path);


const isCollapse = ref(false);
const userAvatar = ref('/path/to/avatar.jpg');
const userName = ref('admin');

const toggleCollapse = () => {
    isCollapse.value = !isCollapse.value;
}

const navigateTo = (path: string) => {
    router.push(path);
};

</script>

<style lang="scss" scoped>
.layout {
    height: 100vh;
}

.layout-header {
    background-color: $backend-layout-header-background;
    color: $backend-layout-header-font;
    border-bottom: 1px solid $backend-layout-header-border;
    padding: 0 20px;
    height: 50px;
    line-height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
}

.collapse {
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin-right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 4px;

    &:hover {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
}


.brand-name {
    font-size: 20px;
    font-weight: bold;
    margin-left: 20px;
}

.user-info {
    display: flex;
    align-items: center;
}

.el-dropdown-link {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.username {
    margin-left: 10px;
    font-size: 16px;
}

.el-link {
    color: backend-layout-header-font;
    text-decoration: none;
}

.layout-aside {
    background-color: $backend-layout-sider-background;
    color: $backend-layout-sider-font;
    transition: width 0.3s ease-in-out, background-color 0.3s ease-in-out;

}


.layout-main {
    padding: 20px;
    background-color: $backend-layout-main-background;
    overflow-y: auto;
    height: calc(100vh - 50px);

    &::-webkit-scrollbar {
        display: none;
        /* 针对 Chrome、Safari 等 WebKit 内核浏览器 */
    }

    scrollbar-width: none;
    /* 针对 Firefox */
    -ms-overflow-style: none;
    /* 针对旧版 IE */
}
</style>